﻿CREATE PROCEDURE [dbo].[yaf_category_save](
                @BoardID    INT,
                @CategoryID INT,
                @Name       NVARCHAR(128),
                @SortOrder  SMALLINT)
AS
    BEGIN
        IF @CategoryID > 0
        BEGIN
            UPDATE yaf_Category
            SET    Name = @Name,
                   SortOrder = @SortOrder
            WHERE  CategoryID = @CategoryID
            SELECT CategoryID = @CategoryID
        END
        ELSE
        BEGIN
            INSERT INTO yaf_Category
                       (BoardID,
                        [Name],
                        SortOrder)
            VALUES     (@BoardID,
                        @Name,
                        @SortOrder)
            SELECT CategoryID = Scope_identity()
        END
    END


